package logic

import (
	"context"
	"go-zero-all/apps/user/pb/pb"

	"go-zero-all/apps/app/internal/svc"
	"go-zero-all/apps/app/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AppLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppLogic {
	return &AppLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AppLogic) App(req *types.Request) (resp *types.Response, err error) {
	result, err := l.svcCtx.UserRPC.Ping(l.ctx, &pb.Request{Ping: req.Name})
	if err != nil {
		return nil, err
	}
	return &types.Response{Message: result.Pong}, nil
}
